package spynx.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class TypeConvert {

	public static int toInt(String string, int defaultValue) {
		try {
			return Integer.parseInt(string);
		}
		catch (NumberFormatException e) {
			return defaultValue;
		}
	}

	public static List<String> splitString(String attribute, String pattern) {
		List<String> result = new ArrayList<String>();
		for(String s: attribute.split(pattern))
			if (s.trim().length() > 0)
				result.add(s.trim());
		return result;
	}

	public static String normalizePath(String path) {
		char charToReplace = File.separatorChar == '\\' ? '/' : '\\';
		return path.replace(charToReplace, File.separatorChar);
	}
}
